package cn.itsource.pethome.basic.service.impl;

import cn.itsource.pethome.basic.mapper.BaseMapper;
import cn.itsource.pethome.basic.query.BaseQuery;
import cn.itsource.pethome.basic.service.IBaseService;
import cn.itsource.pethome.utils.PageResult;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;


public class BaseServiceImpl<T> implements IBaseService<T> {

    @Autowired
    private BaseMapper<T> mapper;
    @Override
    public void save(T t) {
        mapper.save(t);
    }

    @Override
    public void update(T t) {
        mapper.update(t);
    }

    @Override
    public void delete(Long id) {
        mapper.delete(id);
    }

    @Override
    public T loadById(Long id) {
        return mapper.loadById(id);
    }

    @Override
    public List<T> loadAll() {
        return mapper.loadAll();
    }

    @Override
    public PageResult<T> selectByPage(BaseQuery query) {
        Long count = mapper.selectCount(query);
        if (count.equals(0L)){
            return new PageResult<T>();
        }
        PageResult<T> result = new PageResult<>(count,mapper.selectByPage(query));
        return result;
    }

    @Override
    public void deletes(Long[] ids) {
        mapper.deletes(ids);
    }
}
